
testPrinter(
'if (true) callme();',

'if (true)\n\
	callme();',

'if(true)callme()'
);

testPrinter(
'if (true) callme(); else asdf()',

'if (true)\n\
	callme();\n\
else\n\
	asdf();',

'if(true)callme();else asdf()'
);

testPrinter(
'if (a) { if (b) c(); } else d();',

'if (a) {\n\
	if (b)\n\
		c();\n\
} else\n\
	d();',

'if(a){if(b)c()}else d()'
);

testPrinter(
'if (a) if (b) c(); else d();',

'if (a)\n\
	if (b)\n\
		c();\n\
	else\n\
		d();',

'if(a)if(b)c();else d()'
);

// chained IFs should not have a new line after else
testPrinter(
'if (a) x(); else if (b) c();',

'if (a)\n\
	x();\n\
else if (b)\n\
	c();',

'if(a)x();else if(b)c()'
);

testPrinter(
'while(2) {}',

'while (2) {}',

'while(2);'
);

testPrinter(
'while(2) callme()',

'while (2)\n\
	callme();',

'while(2)callme()'
);

testPrinter(
'for(;;) callme();',

'for ( ; ; )\n\
	callme();',

'for(;;)callme()'
);

testPrinter(
'for (var i in {}) e()',

'var i;\n\
for (i in {})\n\
	e();',

'var i;for(i in {})e()'
);

testPrinter(
'for each (var i in {}) e()',

'var i;\n\
for each (i in {})\n\
	e();',

'var i;for each(i in {})e()'
);

testPrinter(
'var i, l;for(i = 0, l = 3; i < l; i++)call();',

'var i, l;\n\
for (i = 0, l = 3; i < l; i++)\n\
	call();',

'var i,l;for(i=0,l=3;i<l;i++)call()'
);

testPrinter(
'while (0, 1) { break; }',

'while (0, 1)\n\
	break;',

'while(0,1)break'
);

testPrinter(
'if (0, 1){};',

'if (0, 1) {}',

'if(0,1);'
);

testPrinter(
'do{}while(0,1);',

'do {} while (0, 1);',

'do;while(0,1)'
);

testPrinter(
'with({}, {}){};',

'with ({}, {}) {}',

'with({},{});'
);

testPrinter(
'asd:while (1) { break asd;}',

'asd:\n\
while (1)\n\
	break asd;',

'asd:while(1)break asd'
);

testPrinter(
'asd:while (0) { continue asd;}',

'asd:\n\
while (0)\n\
	continue asd;',

'asd:while(0)continue asd'
);

testPrinter(
'while(0);',

'while (0) {}',

'while(0);'
);

testPrinter(
'do {} while(0); !1;',

'do {} while (0);\n\
!1;',

'do;while(0)!1'
);

testPrinter(
'switch(a){ case 1: b(); default: c(); d();}',

'switch (a) {\n\
	case 1:\n\
		b();\n\
	default:\n\
		c();\n\
		d();\n\
}',

'switch(a){case 1:b();default:c();d()}'
);

testPrinter(
'try {a();} catch (e if e instanceof Error) {b();} catch(e1) {c();} finally {d()}',

'try {\n\
	a();\n\
} catch (e if e instanceof Error) {\n\
	b();\n\
} catch (e1) {\n\
	c();\n\
} finally {\n\
	d();\n\
}',

'try{a()}catch(e if e instanceof Error){b()}catch(e1){c()}finally{d()}'
);

testPrinter(
'for (i in letters) {\n\
	print(i)\n\
	print(i)\n\
}',

'for (i in letters) {\n\
	print(i);\n\
	print(i);\n\
}',

'for(i in letters){print(i);print(i)}'
);

testPrinter(
'if (1) {\n\
	a();\n\
} else\n\
	b();',

'if (1)\n\
	a();\n\
else\n\
	b();',

'if(1)a();else b()'
);

testPrinter(
'if (1) switch(2) {} else {};',

'if (1)\n\
	switch (2) {\n\
	}\n\
else {}',

'if(1)switch(2){}else;'
);

testPrinter(
'if (1) { switch(2) {} } else {};',

'if (1)\n\
	switch (2) {\n\
	}\n\
else {}',

'if(1)switch(2){}else;'
);

testPrinter(
'if (1) {\n\
	if (2) {\n\
	} else {}\n\
} else if(3) {\n\
	c();\n\
}',

// there is no semicolon after the block which follows the first "else" because Firefox/JSDB chokes when there is one
'if (1)\n\
	if (2) {} else {}\n\
else if (3)\n\
	c();',

'if(1)if(2);else;else if(3)c()'
);

testPrinter(
'if (1) {\n\
	for (i = 1; ; i++)\n\
		if (0) {\n\
		}\n\
} else if (2) {}',

'if (1) {\n\
	for (i = 1; ; i++)\n\
		if (0) {}\n\
} else if (2) {}',

'if(1){for(i=1;;i++)if(0);}else if(2);'
);

testPrinter(
'if (1) if (2) 3; else 4; else 5;',

'if (1)\n\
	if (2)\n\
		3;\n\
	else\n\
		4;\n\
else\n\
	5;',

'if(1)if(2)3;else 4;else 5'
);

testPrinter(
'if (1) a = {}; else {}',

'if (1)\n\
	a = {};\n\
else {}',

'if(1)a={};else;'
);

testPrinter(
'for (var a = 1, b = 2; a, b; a++) {}',

'var a, b;\n\
for (a = 1, b = 2; a, b; a++) {}',

'var a,b;for(a=1,b=2;a,b;a++);'
);

testPrinter(
'if (a) {\n\
	for (;;)\n\
		if (b) {}\n\
} else {};',

'if (a) {\n\
	for ( ; ; )\n\
		if (b) {}\n\
} else {}',

'if(a){for(;;)if(b);}else;'
);

testPrinter(
'if (1) while(0) if (2) 3; else 4; else 5; -1',

'if (1)\n\
	while (0)\n\
		if (2)\n\
			3;\n\
		else\n\
			4;\n\
else\n\
	5;\n\
-1;',

'if(1)while(0)if(2)3;else 4;else 5;-1'
);

testPrinter(
'function a() {\n\
	if (a)\n\
		return b;\n\
	else\n\
		callme();\n\
}',

'function a() {\n\
	if (a)\n\
		return b;\n\
	else\n\
		callme();\n\
}',

'function a(){if(a)return b;else callme()}'
);

testPrinter(
'if(a)for(;;){a}else b;',

'if (a)\n\
	for ( ; ; )\n\
		a;\n\
else\n\
	b;',

'if(a)for(;;)a;else b'
);

testPrinter(
'if (a)\n\
	for ( ; ; ) {\n\
		if (b)\n\
			c();\n\
	}\n\
else\n\
	d();',

'if (a) {\n\
	for ( ; ; )\n\
		if (b)\n\
			c();\n\
} else\n\
	d();',

'if(a){for(;;)if(b)c()}else d()'

);

testPrinter(
'if (1)\n\
	if (2) {}\n\
	else\n\
		for (;;) {\n\
			if (4)\n\
				break\n\
		}\n\
else 2;',

'if (1) {\n\
	if (2) {} else\n\
		for ( ; ; )\n\
			if (4)\n\
				break;\n\
} else\n\
	2;',

'if(1){if(2);else for(;;)if(4)break}else 2'
);

testPrinter(
'if (1) 1, 2; else 2, 3;',

'if (1)\n\
	1, 2;\n\
else\n\
	2, 3;',

'if(1)1,2;else 2,3'
);

testPrinter(
'do a(); while(0);',

'do\n\
	a();\n\
while (0);',

'do a();while(0)'
);

testPrinter(
'if (a) throw {}; else c();',

'if (a)\n\
	throw {};\n\
else\n\
	c();',

'if(a)throw {};else c()'
);

testPrinter(
'function b() { if (a) return {}; else c(); }',

'function b() {\n\
	if (a)\n\
		return {};\n\
	else\n\
		c();\n\
}',

'function b(){if(a)return {};else c()}'
);

testPrinter(
'function d(){\n\
	if (a)\n\
		var b = 1, e = 2;\n\
	else\n\
		c();\n\
}',

'function d() {\n\
	var b, e;\n\
	if (a)\n\
		b = 1, e = 2;\n\
	else\n\
		c();\n\
}',

'function d(){var b,e;if(a)b=1,e=2;else c()}'
);
